package com.powernode.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.powernode.dto.UserDto;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.powernode.domain.User;
import com.powernode.mapper.UserMapper;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(User record) {
        return userMapper.insert(record);
    }

    @Override
    public int insertSelective(User record) {
        return userMapper.insertSelective(record);
    }

    @Override
    public User selectByPrimaryKey(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(User record) {
        return userMapper.updateByPrimaryKey(record);
    }

    @Override
    public User findUser(String username, String password) {
        User user = userMapper.select(username, password);
        return user;
    }

    //分页查询用户数据
    @Override
    public PageInfo<User> queryUserForPage(UserDto userDto) {
        //开启分页拦截
        Page<User> page = PageHelper.startPage(userDto.getPage(), userDto.getLimit());
        List<User> list = userMapper.queryAllUser(userDto);
        PageInfo<User> info = new PageInfo<>(list);
        return info;
    }

    /**
     * 查询所有在职的业务员
     * @return
     */
    @Override
    public List<User> queryAllvailableUser() {
        return this.userMapper.queryAllvailableUser();
    }


}

